package unused;

import lombok.SneakyThrows;

import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.Optional;

public class ReflectUtils {
    @SneakyThrows
    public static Field getField(Class clz, String name) {
        Field declaredField = null;

        for (Class temp = clz; temp != null; temp = temp.getSuperclass()) {

            Optional<Field> first = Arrays.stream(temp.getDeclaredFields())
                    .filter(field -> field.getName().equals(name)).findFirst();
            if(first.isPresent()) {
                declaredField = first.get();
                break;
            }

        }
        return declaredField;
    }
}
